$(document).ready(function(){

///////////////
/*注册页的逻辑*/
//////////////

//点击注册的效果
$('#registerBtn').click(function(){
	
	var username = $('#registerName').val();
	var password = $('#registerPwd').val();
	var nickname = $('#nickname').val();
	
	if(username == ''|| password == ''|| nickname == ''){
		alert('请输入昵称、账号和密码！');
	}else{
		console.log(username+'/'+password);
		$.ajax({
			type:'post',
			url:'../actions/userAction.php',
			data:{
				act				:'checkreg',
				username		:username
			}, 
			async: true,	
			beforeSend: function(){
				showMistAndWait();
			},
			success:function(data){
				console.log('checkreg:'+data);
				if(data == 'reged'){
					alert('此账号已经被注册过！');
					hideMistAndWait();
				}else if(data == 'no reg'){
					$.ajax({
						type:'post',
						url:'../actions/userAction.php',
						data:{
							act				:'register',
							username		:username,
							password		:password,
							nickname		:nickname
						}, 
						async: true,	
						beforeSend: function(){
							showMistAndWait();
						},
						success:function(data){
							
							console.log('register:'+data);
							if(data == 'fail'){
								alert('注册失败！');
							}else if(data == 'success'){
								alert('注册成功！请重新登录');
								window.location.href = 'login.php';
							}
							hideMistAndWait();
						}
					});   
				}
			}
		});
	}
});
});

function showMistAndWait(){				
	$('.waiting').removeClass('hide');
	$('.mist').removeClass('hide');
}

function hideMistAndWait(){				
	$('.waiting').addClass('hide');
	$('.mist').addClass('hide');
}
